<?php

date_default_timezone_set('America/Sao_Paulo');

defined('APPLICATION_PATH')
    or define('APPLICATION_PATH', dirname(__FILE__));

defined('APPLICATION_ENVIRONMENT')
    or define('APPLICATION_ENVIRONMENT', 'development');

Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Db_Table');
Zend_Loader::loadClass('Zend_Controller_Front');
Zend_Loader::loadClass('Zend_View');
Zend_Loader::loadClass('Zend_Translate');

Zend_Loader::loadClass('Fw_Config'); // Load personalized Class
Zend_Loader::loadClass('Fw_Action'); // Load personalized Class
Zend_Loader::loadClass('Fw_View');   // Load personalized Class


Zend_Date::setOptions(array('format_type' => 'php'));

// action helpers
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . 'controllers/helpers');
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');

// CONTROLLER DIRECTORY SETUP - Point the front controller to your action controller directory.
$frontController = Zend_Controller_Front::getInstance();
$frontController->addModuleDirectory(APPLICATION_PATH .'modules')
				->setDefaultModule('index')
				->throwExceptions(true);
				//->dispatch();

// LAYOUT SETUP - Setup the layout component
// VIEW SETUP - Initialize properties of the view object

if(FW_MODE == 'client') {
	Zend_Layout::startMvc(PROJECT_PATH);
	$view = Zend_Layout::getMvcInstance()->getView();
} else {
	Zend_Layout::startMvc(PROJECT_PATH);
	$view = Zend_Layout::getMvcInstance()->getView()->addScriptPath(APPLICATION_PATH .'views/templates/');
}
$view->doctype('XHTML1_STRICT');

$configuration = new Zend_Config_Xml(PROJECT_PATH . 'config/app.xml', APPLICATION_ENVIRONMENT);

Zend_Registry::set('config', $configuration);
Zend_Registry::set('env', APPLICATION_ENVIRONMENT);

if($configuration->debug) {
	error_reporting(E_ALL | E_STRICT);
	ini_set('display_errors', 'on');
}

$dbAdapter = Zend_Db::factory($configuration->db);
Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);

$registry = Zend_Registry::getInstance();
$registry->configuration = $configuration;
$registry->dbAdapter     = $dbAdapter;

$translate = new Zend_Translate('ini', APPLICATION_PATH .'languages/pt-br.ini', 'pt-br');
Zend_Registry::set('Zend_Translate', $translate);

// APPLICATION ENVIRONMENT - Set the current environment
// $frontController->setParam('env', APPLICATION_ENVIRONMENT);

// CLEANUP - remove items from global scope
unset($frontController, $view, $configuration, $dbAdapter, $registry);